package com.tarena.lbs.basic.web.dao.repository.impl;

import com.tarena.lbs.basic.web.dao.mapper.UserMapper;
import com.tarena.lbs.basic.web.dao.mapper.UserTagsMapper;
import com.tarena.lbs.basic.web.dao.repository.UserRespository;
import com.tarena.lbs.pojo.basic.bo.UserBO;

import com.tarena.lbs.pojo.basic.dos.UserDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

@Slf4j
@Component
public class UserRepositoryImpl implements UserRespository {
   @Autowired
   private UserMapper userMapper;
    @Autowired
    private UserTagsMapper userTagsMapper;

    @Override
    public void saveUser(UserBO userBO) {
        UserDO userDO = new UserDO();
        BeanUtils.copyProperties(userBO,userDO);
        userMapper.saveUser(userDO);
    }

    @Override
    public UserBO getUserByPhone(String phone) {
        log.debug("手机小程序登录判断手机号是否存在入参 phone"+phone);
        UserDO userDO = userMapper.selectUserByPhone(phone);
        if (!ObjectUtils.isEmpty(userDO)){
            UserBO userBO = new UserBO();
            BeanUtils.copyProperties(userDO,userBO);
            return userBO;
        }
        return null;
    }

    @Override
    public UserBO getUserById(Integer userId) {
        log.debug("手机小程序登录湖区用户详细信息 userId="+userId);
        UserDO userDO = userMapper.selectUserById(userId);
        if (!ObjectUtils.isEmpty(userDO)){
            UserBO userBO = new UserBO();
            BeanUtils.copyProperties(userDO,userBO);
            return userBO;
        }
        return null;
    }

    @Override
    public void updateUserStatus(Integer userId, int i) {
        UserDO userDO = new UserDO();
        userDO.setId(userId);
        userDO.setStatus(i);
        userMapper.updateUserStatus(userDO);
    }
}
